Just as we can read from parts of a matrix, we can also write to part
of a matrix. You have seen assignment of a whole matrix to a variable
in previous examples — now lets look at partial assignment. We can
re-assign single elements, or groups of elements. For single elements,
we just specify a reference to that element (either row and column or
vector notation — it doesn't matter), and equate it to the new value.
For a group of elements, we have to specify a range, and equate that to
a matrix of equal size. Here are some examples:
> yellow = rand(3,3)
yellow =
0.167 0.91 0.265
0.655 0.112 0.7
0.129 0.299 0.95
> yellow[2;2] = 967
yellow =
0.167 0.91 0.265
0.655 967 0.7
0.129 0.299 0.95
> yellow[2,3;1,2] = [100, 200; 300, 400]
yellow =
0.167 0.91 0.265
100 200 0.7
300 400 0.95